package com.lazyfragmentdemo;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    //fragment 集合
    ArrayList<Fragment> list;
    private FragmentManager fm;
    private ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mViewPager = (ViewPager) findViewById(R.id.viewPager);
        initTabLayout();
    }

    private void initTabLayout() {
        fm = getSupportFragmentManager();
        //和viewpager相关联
        list = new ArrayList<>();
        //听课记录
        FragmentDemo demo1 = FragmentDemo.newInstance(1, true);
        //听课交流
        FragmentDemo demo2 = FragmentDemo.newInstance(2, true);
        FragmentDemo demo3 = FragmentDemo.newInstance(3, true);
        list.add(demo1);
        list.add(demo2);
        list.add(demo3);

        List<String> strings = new ArrayList<>();
        strings.add("1");
        strings.add("2");
        strings.add("3");

        Viewpager_Adapter adapter = new Viewpager_Adapter(fm, list, strings);
        mViewPager.setAdapter(adapter);
        //mViewPager.setOffscreenPageLimit(2);
    }
}
